package com.sinog.biz.util;

import com.sinog.core.util.DateUtil;
import com.sinog.core.util.JsonUtil;
import com.sinog.core.utilbean.Constants;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Types;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @desc jdbc工具类
 * @author lzq
 * @date 2021-06-24 11:56
 */
@Slf4j
@Component
@Configuration
public class JdbcUtils {

    private static Connection conn;
    private static Statement sm;
    private static String driver;
    private static String url;
    private static String userName;
    private static String password;


    @Value("${spring.datasource.driverClassName}")
    public void setDriver(String driver) {
        JdbcUtils.driver = driver;
    }

    @Value("${spring.datasource.url}")
    public void setUrl(String url) {
        JdbcUtils.url = url;
    }

    @Value("${spring.datasource.username}")
    public void setUserName(String userName) {
        JdbcUtils.userName = userName;
    }

    @Value("${spring.datasource.password}")
    public void setPassword(String password) {
        byte[] bytes = DesCryptoGraphy.hexStringToByte(password);
        byte[] pwdb = DesCryptoGraphy.desCbcDecrypt(bytes,DesCryptoGraphy.KEY.getBytes());
        assert pwdb != null;
        JdbcUtils.password = new String(pwdb);
    }

    /**
     * 描述
     * @param priNum 罪犯编号
     * @param sql sql 执行sql
     * int failurenu 失败次数
     * @param localCode 本地行政区划编码
     * @param inCode 目的省份行政区划编码
     * @return String
     */
    public static String createMiddleSql(Object priNum,String sql,int failurenum,Object localCode,Object inCode) {
        String type = "2";
        String state = "2";
        String reason = "";
        Date date = new Date();
        return "INSERT INTO middle (id,pri_num,type,state,statement,create_time,update_time,failurenum,reason,create_province_code,in_province_code)" + " VALUES (" + JsonUtil.toText(IdGen.strid()) + "," + JsonUtil.toText(priNum) + "," + JsonUtil.toText(type) + "," + state + "," + JsonUtil.toText(sql) + "," + JsonUtil.toText(DateUtil.returnStringTime(date,"yyyy-MM-dd HH:mm:ss")) + "," + JsonUtil.toText(DateUtil.returnStringTime(date,"yyyy-MM-dd HH:mm:ss")) + "," + JsonUtil.toText(failurenum) + "," + JsonUtil.toText(reason) + "," + JsonUtil.toText(localCode) + "," + JsonUtil.toText(inCode) + ")";
    }

    /**
     * 保存文件信息到司法部中间库 file_video 表中
     * @param originalFilename 文件名称
     * @param suffixType 文件类型
     * @param localPath 本地服务器文件路径
     * @param ftpPath ftp服务器文件路径
     * @param createProvinceCode 创建文件的省份标识
     * @param updateProvinceCode 修改文件的省份标识
     * @return String
     */
    public static String insertMiddleVideoSql(String originalFilename,String suffixType,String desc,String localPath,String ftpPath,String createProvinceCode,String updateProvinceCode) {
        Date date = new Date();
        return "INSERT INTO file_video (name,type,descriton,localPath,ftpPath,createTime,updateTime,createProvinceCode,updateProvinceCode)" + " VALUES (" + JsonUtil.toText(originalFilename) + "," + JsonUtil.toText(suffixType) + "," + JsonUtil.toText(desc) + ","+JsonUtil.toText(localPath) + "," + JsonUtil.toText(ftpPath) + "," + JsonUtil.toText(DateUtil.returnStringTime(date,"yyyy-MM-dd HH:mm:ss")) + "," + JsonUtil.toText(DateUtil.returnStringTime(date,"yyyy-MM-dd HH:mm:ss")) + "," + JsonUtil.toText(createProvinceCode) + "," + JsonUtil.toText(updateProvinceCode) + ")";
    }

    /**
     * 根据文件名称删除文件
     * @param originalFilename 文件名称
     * @return String
     */
    public static String updateMiddleVideoSqlByName(String originalFilename) {
        return "delete from  file_video where name="+JsonUtil.toText(originalFilename);
    }

    /**
     * 根据文件名称查询文件
     * @param originalFilename 文件名称
     * @return String
     */
    public static String selectMiddleVideoSqlByName(String originalFilename) {
        return "select ftpPath from  file_video where name="+JsonUtil.toText(originalFilename);
    }

    /**
     * 根据文件名称查询文件是否存在
     * @param originalFilename 文件名称
     * @return String
     */
    public static String selectLocalSqlByName(String originalFilename) {
        return "select count(1) from  file_video where localPath="+JsonUtil.toText(originalFilename);
    }

    /**
     * 动态查询上架的培训文件
     * @param flag 0：上架 1：下架
     * @return String
     */
    public static String findMiddleVideosSql(String flag) {
        if(StringUtils.isNotBlank(flag) && !Constants.NumberStr.NUM_STR_FU_ONE.equals(flag)) {
            return "select name,type,descriton,localPath,ftpPath,date_format(updateTime,'%Y-%m-%d') as updateTime,createProvinceCode,updateProvinceCode,flag from file_video where flag="+flag;
        } else {
            return "select id,name,type,descriton,localPath,ftpPath,date_format(createTime,'%Y-%m-%d %H:%i:%s') as createTime,date_format(updateTime,'%Y-%m-%d %H:%i:%s') as updateTime,createProvinceCode,updateProvinceCode,flag from file_video";
        }
    }

    /**
     * 更改文件的状态(上架与下架）
     * @param originalFilename 原文件名
     * @param status 状态 0：上架 1：下架
     * @param codeName 更新省份
     * @return String
     */
    public static String updateVideosSql(String originalFilename,String status,String codeName) {
        Date date = new Date();
        return "update file_video set flag="+ status + ",updateTime="+ JsonUtil.toText(DateUtil.returnStringTime(date,"yyyy-MM-dd HH:mm:ss")) + ",updateProvinceCode="+ JsonUtil.toText(codeName) + " where name="+JsonUtil.toText(originalFilename);
    }

    /**
     * 描述
     * @param tableName tableName
     * @param param param
     * @param value value
     * @param param1 param1
     * @param value1 value1
     * @param param2 param2
     * @param value2 value2
     * @return List<String>
     */
    public static List<String> getInsertSql(String tableName,String param,Object value,String param1,String value1,String param2,String value2) {
        List<String> listSql;
        //连接数据库
        connectSql(driver,url,userName,password);
        listSql = createSqlOne(tableName,param,value,param1,value1,param2,value2,"");
        List<String> strings = null;
        //执行sql并拼装
        try {
            strings = executeSql(tableName,conn,sm,listSql);
        } catch(SQLException throwables) {
            log.error(throwables.getMessage());
        }
        return strings;
    }

    /**
     * 获取拼接sql
     * @param tableName  表名
     * @param param 原sql的参数
     * @param value 原sql的值
     * @param conditionLength   update语句用到的，where后面的参数个数
     * @param type 1-获取update拼接语句，2-获取insert拼接语句，3-获取delete拼接语句
     * @return 拼接好的sql
     */
    public static String getAppendSql(String tableName,List<String> param,List<String> value,Integer conditionLength,Integer type) {
        String sql;
        //连接数据库
        connectSql(driver,url,userName,password);
        //获取现在表结构的参数信息
        List<String> columns = getTableInformation(tableName);
        if (Constants.Number.NUM_ONE.equals(type)) {
            //拼接update的sql语句
            sql = appendUpdateSql(tableName, param, value, columns, conditionLength);
        } else if (Constants.Number.NUM_TWO.equals(type)) {
            //拼接Insert的sql语句
            sql = appendInsertSql(tableName, param, value, columns);
        }else {
            //拼接delete的sql语句
            sql = appendDeleteSql(tableName, param, value, columns);
        }
        return sql;
    }
    /**
     * 拼接delete语句
     * @param tableName 表名
     * @param params    参数
     * @param values    值
     * @param columns   该表的所有列
     * @return  拼接完成的delete语句
     */
    private static String appendDeleteSql(String tableName, List<String> params, List<String> values, List<String> columns) {
        StringBuilder sb = new StringBuilder();
        sb.append("delete from ");
        sb.append(tableName);
        sb.append(" where ");
        for (int i = 0; i < params.size(); i++) {
            String name = params.get(i);
            String value = values.get(i);
            //todo：处理字段的变更,需要补充
            if ("pid".equalsIgnoreCase(name) || "prinum".equalsIgnoreCase(name)) {
                name = "pri_num";
            }
            if ("edit_time".equalsIgnoreCase(name)) {
                name = "update_time";
            }
            //如果现在表结构中存在当前字段，则进行拼接
            for (String column : columns) {
                if (name.equalsIgnoreCase(column)) {
                    sb.append(name);
                    sb.append(" = ");
                    sb.append(value);
                    sb.append("and ");
                    break;
                }
            }
        }
        return sb.substring(0, sb.lastIndexOf("and"));
    }
    private static String appendUpdateSql(String tableName, List<String> params, List<String> values, List<String> columns,Integer ConditionLength) {
        StringBuilder sb = new StringBuilder();
        StringBuilder sb1 = new StringBuilder();
        //
        sb.append("update ").append(tableName).append(" set ");
        sb1.append(" where ");
        //这里只循环拼接where条件之前的参数和值
        for (int i = 0; i < params.size()- ConditionLength; i++) {
            String name = params.get(i);
            String value = values.get(i);
            //todo：处理字段的变更,需要补充
            if ("pid".equalsIgnoreCase(name) || "prinum".equalsIgnoreCase(name)) {
                name = "pri_num";
            }
            if ("edit_time".equalsIgnoreCase(name)) {
                name = "update_time";
            }
            //如果现在表结构中存在当前字段，则进行拼接
            for (String column : columns) {
                if (name.equalsIgnoreCase(column)) {
                    sb.append(name);
                    sb.append(" = ");
                    sb.append(value);
                    sb.append(", ");
                    break;
                }
            }
        }
        //这里只拼接where之后的参数和值
        for (int i = params.size()- ConditionLength; i < params.size(); i++) {
            String name = params.get(i);
            String value = values.get(i);
            //todo：处理字段的变更,需要补充
            if ("pid".equalsIgnoreCase(name) || "prinum".equalsIgnoreCase(name)) {
                name = "pri_num";
            }
            if ("edit_time".equalsIgnoreCase(name)) {
                name = "update_time";
            }
            //如果现在表结构中存在当前字段，则进行拼接
            for (String column : columns) {
                if (name.equalsIgnoreCase(column)) {
                    sb1.append(name);
                    sb1.append(" = ");
                    sb1.append(value);
                    sb1.append(" and ");
                    break;
                }
            }
        }
        String substring = sb.substring(0, sb.lastIndexOf(","));
        String substring1 = sb1.substring(0, sb1.lastIndexOf("and"));
        return substring+substring1;
    }

    /**
     * 拼接insert语句
     * @param tableName 表名
     * @param params    参数
     * @param values    值
     * @param columns   当前表的所有列
     * @return  拼接完成的sql语句
     */
    private static String appendInsertSql(String tableName, List<String> params, List<String> values, List<String> columns) {
        //处理param
        StringBuilder paramBuffer = new StringBuilder();
        StringBuilder valueBuffer = new StringBuilder();
        //paramBuffer拼接values的前半部分
        paramBuffer.append("insert into ").append(tableName).append(" (");
        //valueBuffer拼接values的后半部分
        valueBuffer.append(" values (");
        //循环处理，参数和值是对应的
        for (int i = 0; i < params.size(); i++) {
            String name = params.get(i).trim();
            String value = values.get(i);
            //todo：处理字段的变更,需要补充
            if ("pid".equalsIgnoreCase(name) || "prinum".equalsIgnoreCase(name)) {
                name = "pri_num";
            }
            if ("edit_time".equalsIgnoreCase(name)) {
                name = "update_time";
            }
            //如果现在表结构中存在当前字段，则进行拼接
            for (String column : columns) {
                if (name.equalsIgnoreCase(column)) {
                    paramBuffer.append(name).append(",");
                    valueBuffer.append(value).append(",");
                    break;
                }
            }
        }
        //需要处理paramBuffer和valueBuffer中最后的逗号，并且拼接上”)“
        String s1 = paramBuffer.substring(0, paramBuffer.lastIndexOf(","));
        String s2 = valueBuffer.substring(0, valueBuffer.lastIndexOf(","));
        s1 += ")";
        s1 += s2;
        return s1;
    }

    /**
     * 目的：根据表名获取表中所有字段
     * @param tableName 表名称
     * @return 当前表的所有字段集合
     */
    private static List<String> getTableInformation(String tableName) {
        //装载所有字段的集合
        List<String> stringList = new ArrayList<>(16);
        String str = url.replace("//", "");
        //通过url获取数据库名
        String schemaName = str.substring(str.indexOf("/")+1, str.indexOf("?"));
        //查询当前表的所有字段
        String localSql = "select COLUMN_NAME as 'name'  from information_schema.`COLUMNS` c where TABLE_SCHEMA ='"+schemaName+"' and TABLE_NAME ='"+tableName+"';";
        try {
            ResultSet resultSet = sm.executeQuery(localSql);
            while (resultSet.next()) {
                stringList.add(resultSet.getString("name"));
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        return stringList;
    }

    /**
     * 描述
     * @param tableName tableName
     * @param param param
     * @param value value
     * @param param1 param1
     * @param value1 value1
     * @param param2 param2
     * @param value2 value2
     * @return List<String>
     */
    public static List<String> getInsertSql1(String tableName,String param,Object value,String param1,String value1,String param2,String value2) {
        List<String> listSql;
        //连接数据库
        connectSql(driver,url,userName,password);
        listSql = createSqlOne(tableName,param,value,param1,value1,param2,value2,"1");
        List<String> strings = null;
        //执行sql并拼装
        try {
            strings = executeSql(tableName,conn,sm,listSql);
        } catch(SQLException throwables) {
            log.error(throwables.getMessage());
        }
        return strings;
    }

    /**
     * 拼装查询语句
     * @param tableName tableName
     * @param param param
     * @param value value
     * @param param1 param1
     * @param value1 value1
     * @param param2 param2
     * @param value2 value2
     * @param type type
     * @return 返回select集合
     */
    private static List<String> createSqlOne(String tableName,String param,Object value,String param1,String value1,String param2,String value2,String type) {
        List<String> listSql = new ArrayList<>(16);
        StringBuilder sb = new StringBuilder(16);
        if(Constants.NumberStr.NUM_STR_ONE.equals(type)) {
            sb.append("SELECT * FROM").append(" ").append(".").append(tableName).append(" where ").append(param)
              .append(" in( ").append(" select xjid from xj_receipt where pri_num ='  ").append(value).append("')");
        } else {
            sb.append("SELECT * FROM").append(" ").append(".").append(tableName).append(" where ").append(param)
              .append("='").append(value).append("'");
            if(!StringUtils.isEmpty(param1)) {
                sb.append(" and ").append(param1).append("='").append(value1).append("'");
            }
            if(!StringUtils.isEmpty(param2)) {
                sb.append(" and ").append(param2).append("='").append(value2).append("'");
            }
        }
        listSql.add(sb.toString());
        return listSql;
    }

    /**
     * 连接数据库 创建statement对象
     * @param driver driver
     * @param url url
     * @param userName userName
     * @param password password
     */
    public static void connectSql(String driver,String url,String userName,String password) {
        try {
            Class.forName(driver).newInstance();
            conn = DriverManager.getConnection(url,userName,password);
            sm = conn.createStatement();
        } catch(Exception e) {
            log.error("发生异常:",e);
        }
    }

    /**
     * 执行sql并返回插入sql
     * @param conn conn
     * @param sm sm
     * @param listSql listSql
     * @return List<String>
     */
    public static List<String> executeSql(String tableName,Connection conn,Statement sm,List<String> listSql) throws SQLException {
        List<String> columnNameAndColumeValue = new ArrayList<>(16);
        try {
            columnNameAndColumeValue = getColumnNameAndColumeValue(tableName,sm,listSql);
        } catch(SQLException e) {
            log.error("发生异常:",e);
        } finally {
            if(null != sm) {
                sm.close();
            }
            if(null != conn) {
                conn.close();
            }
        }
        return columnNameAndColumeValue;
    }

    /**
     * 获取列名和列值
     * @param sm sm
     * @param listSql listSql
     * @return List<String>
     */
    private static List<String> getColumnNameAndColumeValue(String tableName,Statement sm,List<String> listSql) throws SQLException {
        List<String> stringList = new ArrayList<>(16);
        if(!listSql.isEmpty()) {
            for(String s : listSql) {
                String sql = String.valueOf(s);
                ResultSet rs = sm.executeQuery(sql);
                ResultSetMetaData rsmd = rs.getMetaData();
                int columnCount = rsmd.getColumnCount();
                while(rs.next()) {
                    StringBuffer columnName = new StringBuffer(16);
                    StringBuffer columnValue = new StringBuffer(16);
                    for(int i = 1; i <= columnCount; i++) {
                        if(null != rs.getString(i)) {
                            if("xj_receipt".equalsIgnoreCase(tableName) && "id".equalsIgnoreCase(rsmd.getColumnName(i))) {
                                continue;
                            }
                            String value = rs.getString(i).trim();
                            if(Constants.Number.NUM_ONE == i) {
                                columnName.append(rsmd.getColumnName(1));
                            } else {
                                if("xj_receipt".equalsIgnoreCase(tableName) && Constants.Number.NUM_TWO == i) {
                                    columnName.append(rsmd.getColumnName(i));
                                } else {
                                    columnName.append(",").append(rsmd.getColumnName(i));
                                }
                            }
                            if(Types.CHAR == rsmd.getColumnType(i) || Types.VARCHAR == rsmd.getColumnType(i) || Types.LONGVARCHAR == rsmd.getColumnType(i)) {
                                if(Constants.Number.NUM_ONE == i) {
                                    columnValue.append("'").append(value).append("',");
                                } else if(i == columnCount) {
                                    columnValue.append("'").append(value).append("'");
                                } else {
                                    columnValue.append("'").append(value).append("'").append(",");
                                }
                            } else if(Types.SMALLINT == rsmd.getColumnType(i) || Types.INTEGER == rsmd.getColumnType(i) || Types.BIGINT == rsmd.getColumnType(i) || Types.FLOAT == rsmd.getColumnType(i) || Types.DOUBLE == rsmd.getColumnType(i) || Types.NUMERIC == rsmd.getColumnType(i) || Types.DECIMAL == rsmd.getColumnType(i)) {
                                if(Constants.Number.NUM_ONE == i) {
                                    columnValue.append(value).append(",");
                                } else if(i == columnCount) {
                                    columnValue.append(value);
                                } else {
                                    columnValue.append(value).append(",");
                                }
                            } else if(Types.DATE == rsmd.getColumnType(i) || Types.TIME == rsmd.getColumnType(i) || Types.TIMESTAMP == rsmd.getColumnType(i)) {
                                if(Constants.Number.NUM_ONE == i) {
                                    columnValue.append("'").append(value).append("',");
                                } else if(i == columnCount) {
                                    columnValue.append("'").append(value).append("'");
                                } else {
                                    columnValue.append("'").append(value).append("'").append(",");
                                }
                            } else {
                                if(i != columnCount) {
                                    columnValue.append(value).append(",");
                                }
                            }
                        }
                    }
                    stringList = insertSql(tableName,columnName,columnValue);
                }
            }
        }
        return stringList;
    }

    /**
     * 拼装insertsql 放到全局list里面
     * @param columnName columnName
     * @param columnValue columnValue
     * @return List<String>
     */
    private static List<String> insertSql(String tableName,StringBuffer columnName,StringBuffer columnValue) {
        List<String> insertList = new ArrayList<>(16);
        StringBuilder insertsql = new StringBuilder(16);
        if(Constants.SpecialChar.NUM_CHAR_C.equals(columnValue.substring(columnValue.length() - 1))) {
            String substring = columnValue.substring(0,columnValue.length() - 1);
            columnValue = new StringBuffer(substring);
        }
        insertsql.append("INSERT INTO").append(" ").append(tableName).append("(").append(columnName.toString())
                 .append(")").append("VALUES").append("(").append(columnValue).append(");");
        insertList.add(insertsql.toString());
        return insertList;
    }

    /**
     * 修改表中字段顺序
     * 2.4.0 执行sql
     * @param dataBase1 数据库1
     * @return 执行的sql语句集合
     */
    public static List<String> executeSql2(String dataBase1) throws SQLException {
        // 定义执行数据库sql语句
        // id='" + id + "'";
        String columnName1 = "";
        StringBuffer buffer = new StringBuffer(16);
        String sql1 = "select table_name from information_schema.columns where table_schema = '"+dataBase1+"' group by table_name";
        String sql2 = "select * from information_schema.columns where table_schema = '"+dataBase1+"' and table_name = ? order by ORDINAL_POSITION";
        ResultSet resultSet = sm.executeQuery(sql1);
        while (resultSet.next()) {
            String tableName = resultSet.getString(1);
            PreparedStatement psmt = conn.prepareStatement(sql2);
            psmt.setString(1,tableName);
            ResultSet resultSet1 = psmt.executeQuery();
            while (resultSet1.next()) {
                // 获取执行返回值结果
                String columnName = resultSet1.getString(4);
                String columnType = resultSet1.getString(16);
                String characterSetName = resultSet1.getString(14);
                String collationName = resultSet1.getString(15);
                String columnDefault = resultSet1.getString(6);
                String isNullAble = resultSet1.getString(7);
                String columnComment = resultSet1.getString(20);
                if("id".equalsIgnoreCase(columnName)) {
                    if(columnType.contains("long")
                            || columnType.contains("int") || columnType.contains("bigint")) {
                        buffer.append("alter table ").append(tableName).append(" change ")
                                .append("`").append(columnName).append("`").append(" `")
                                .append(columnName).append("`");
                                if(StringUtils.isNotBlank(columnDefault)) {
                                    buffer.append(" default ").append("'").append(columnDefault).append("'");
                                }
                        buffer.append(columnType).append(" comment ").append("'").append(columnComment).append("'")
                                .append(" after ").append("`").append(columnName1).append("`");
                    } else {
                        buffer.append("alter table ").append(tableName).append(" change ")
                                .append("`").append(columnName).append("`").append(" `")
                                .append(columnName).append("` ")
                                .append(columnType).append(" charset ").append(characterSetName)
                                .append(" collate ").append(collationName).append(" ");
                        if("no".equalsIgnoreCase(isNullAble)) {
                            buffer.append(" not ");
                        }
                        if(StringUtils.isNotBlank(columnDefault)) {
                            buffer.append(" default ").append("'").append(columnDefault).append("'");
                        }
                        buffer.append(" null ").append(" comment ").append("'").append(columnComment).append("'");
                    }
                } else if ("datetime".equalsIgnoreCase(columnType) || "timestamp".equalsIgnoreCase(columnType)
                    || "date".equalsIgnoreCase(columnType) || "time".equalsIgnoreCase(columnType)
                    || "year".equalsIgnoreCase(columnType) || columnType.contains("long")
                    || columnType.contains("int") || columnType.contains("bigint")){
                    buffer.append("alter table ").append(tableName).append(" change ")
                            .append("`").append(columnName).append("`").append(" `")
                            .append(columnName).append("`").append(columnType);
                    if(StringUtils.isNotBlank(columnDefault)) {
                        buffer.append(" default ").append("'").append(columnDefault).append("'");
                    }
                    buffer.append(" comment ").append("'").append(columnComment).append("'")
                            .append(" after ").append("`").append(columnName1).append("`");
                } else {
                    buffer.append("alter table ").append(tableName).append(" change ")
                            .append("`").append(columnName).append("`").append(" `")
                            .append(columnName).append("` ")
                            .append(columnType).append(" charset ").append(characterSetName)
                            .append(" collate ").append(collationName).append(" ");
                            if("no".equalsIgnoreCase(isNullAble)) {
                                buffer.append(" not ");
                            }
                            if(StringUtils.isNotBlank(columnDefault)) {
                                buffer.append(" null ").append(" default ").append("'").append(columnDefault).append("'");
                            }
                            buffer.append(" null ").append(" comment ").append("'").append(columnComment).append("'")
                            .append(" after ").append("`").append(columnName1).append("`");
                }
                buffer.append(";");
                log.info(String.valueOf(buffer));
                buffer.setLength(0);
                columnName1 = columnName;
            }
            columnName1 = null;
        }
        return null;
    }
}